﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Npgsql;

namespace ServiciosGeograficos.Persistencia
{
    public class PostgresDAO
    {
        public PostgresDAO()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private NpgsqlConnection darConexion()
        {
            return new NpgsqlConnection("server=localhost;database=template_postgis;uid=postgres;pwd=admin;port=5432");
        }

        public DataSet ejecutarQuery(String query, String nmTabla)
        {
            NpgsqlConnection conexion = darConexion();
            DataSet dataSet = new DataSet();
            NpgsqlCommand rsCommand = conexion.CreateCommand();
            NpgsqlDataAdapter rsDATAadapter = new NpgsqlDataAdapter();
            rsCommand.CommandText = query;
            rsDATAadapter.SelectCommand = rsCommand;
            rsDATAadapter.Fill(dataSet, nmTabla);
            return dataSet;
        }

        public DataSet ejecutarQuery(DataSet dataSet,String query, String nmTabla)
        {
            NpgsqlConnection conexion = darConexion();
            NpgsqlCommand rsCommand = conexion.CreateCommand();
            NpgsqlDataAdapter rsDATAadapter = new NpgsqlDataAdapter();
            rsCommand.CommandText = query;
            rsDATAadapter.SelectCommand = rsCommand;
            rsDATAadapter.Fill(dataSet, nmTabla);
            return dataSet;
        }
    }
}
